package com.five.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.five.dao.ClubDao;
import com.five.pojo.Club;
import com.five.pojo.ClubJoin;
import com.five.pojo.PageBean;
import com.five.service.ClubService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author lenovo
 */
@Service
public class ClubServiceImpl implements ClubService {

    @Autowired
    ClubDao clubDao;
    @Override
    public List<Club> getAll() {
        QueryWrapper<Club> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("*");
        List<Club> list = clubDao.selectList(queryWrapper);
        return list;
    }

 //分页
    @Override
    public PageBean page(Integer page, Integer pageSize , String cName , String cType){
        //1.设置分页参数
        PageHelper.startPage(page , pageSize);
        //2.执行查询
        List<Club> clubList = clubDao.list2(cName , cType);
        Page<Club> p = (Page<Club>) clubList;
        //3.封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal() , p.getResult());
        return pageBean;
    }

    //申请入团
    @Override
    public void addClub(ClubJoin clubJoin) {
        clubJoin.setCJoinTime(LocalDateTime.now());
        clubDao.addClub(clubJoin);
    }

    //查询入团申请信息
    @Override
    public List<ClubJoin> getAllJoin() {
        List<ClubJoin> list = clubDao.getAllJoin();
        return list;
    }



}
